package ext.tianma.bom.service.sqe;

import java.io.PrintWriter;

import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
@RequestMapping({ "/sqe"})
public class SQEPartController {
	
	@RequestMapping(value = "/sqePart", method = {
			RequestMethod.POST, RequestMethod.GET 
			})
	public void getSQEPart(
			@RequestParam(value = "partNum", required = true) String partNum,
			@RequestParam(value = "proNum", required = true) String proNum,
			@RequestParam(value = "partSupplier", required = false) String partSupplier,
			HttpServletResponse response) throws Exception {
		boolean enforce = wt.session.SessionServerHelper.manager
				.setAccessEnforced(false);
		PrintWriter out = response.getWriter();
		response.setContentType("text/html;charset=UTF-8");
		try {
			String result = SQEPartService.getShowData(partNum.trim(), proNum.trim(), partSupplier.trim());
			out.print(result);
		} catch (Throwable e) {
			e.printStackTrace();
		} finally {
			wt.session.SessionServerHelper.manager.setAccessEnforced(enforce);
		}
	}
	
	@RequestMapping(value = "/sqeExportExcel", method = {
			RequestMethod.POST, RequestMethod.GET 
			})
	public void getSQEPartExcel(
			@RequestParam(value = "partNum", required = true) String partNum,
			@RequestParam(value = "proNum", required = true) String proNum,
			@RequestParam(value = "partSupplier", required = false) String partSupplier,
			HttpServletResponse response) throws Exception {
		boolean enforce = wt.session.SessionServerHelper.manager
				.setAccessEnforced(false);
		PrintWriter out = response.getWriter();
		response.setContentType("text/html;charset=UTF-8");
		try {
			String result = SQEPartService.getExcelData(partNum.trim(), proNum.trim(), partSupplier.trim());
			out.print(result);
		} catch (Throwable e) {
			e.printStackTrace();
		} finally {
			wt.session.SessionServerHelper.manager.setAccessEnforced(enforce);
		}
	}
	
}
